package com.eascs.workflow.sys.dubbo;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.web.sso.User;
import com.eascs.workflow.common.entity.sys.HREmployeeAuditor;
import com.eascs.workflow.common.service.sys.EmployeeService;
import com.eascs.workflow.sys.dao.SysUserDao;
import com.eascs.workflow.sys.user.EaSsoDao;

@Service
public class EmployeeDubboService implements EmployeeService {
	private static Logger log = LoggerFactory.getLogger(EmployeeDubboService.class);
	@Autowired
	private EaSsoDao eaSsoDao;
	@Autowired
	private SysUserDao sysUserDao;

	@Override
	public User getUserByAccount(String account) {
		User user  = eaSsoDao.getUserByAccount(StringUtils.trimToEmpty(account), User.class);
		if (user == null || !StringUtils.equalsIgnoreCase(user.getStatus(), "0")) {
			log.info("员工离职/账号冻结");
			throw new RuntimeException("员工离职/账号冻结");
		}
		return user;
	}

	@Override
	public User getUserByNo(String userNo) {
		return eaSsoDao.getUserByNo(userNo, User.class);
	}

	@Override
	public HREmployeeAuditor getAuditorWithNoAndType(String employNo, String auditorType) {
		return sysUserDao.getEmployeeAuditor(employNo, auditorType);
	}

	@Override
	public List<HREmployeeAuditor> getAuditorWithNo(String employNo) {
		return sysUserDao.getAuditorWithNo(employNo);
	}

	@Override
	public Boolean checkEmpIn380System(String userNo) {
		User user = sysUserDao.getUserInSystem(userNo);
		if (user != null) {
			return true;
		}
		return false;
	}

}
